﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Smartmanufact
{
    public partial class Add_user : Form
    {
        public Add_user()
        {
            InitializeComponent();
            comboBox_limit.Items.Add("user");
            comboBox_limit.Items.Add("admin");
            comboBox_limit.Items.Add("none");
        }

        private void Add_user_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            // 增加一行
            try
            {
                string name = textBox_username.Text.Trim();                  // 用户名
                string passworid = textBox_password.Text.Trim();             // 密  码
                string limit = comboBox_limit.Text.Trim();                   // 权限
                if (name == "") { MessageBox.Show("用户名不能为空！"); return; }
                if (passworid == "") { MessageBox.Show("密码不能为空！"); return; }
                if (limit == "") { MessageBox.Show("必须选择权限！"); return; }

                //  判断用户名在表中是否已经存在
                DataSet ds = MainView.mysql.sql_search_database("select * from usertable");
                int rowcount = ds.Tables[0].Rows.Count;
                


                bool right= MainView.mysql.excute_sql("insert into usertable values ('" + name + "','" + passworid + "','" + limit + "')");
                if (right == false) { MessageBox.Show("增加用户出现错误！"); return; }
                this.Dispose();
            }
            catch { MessageBox.Show("添加过程中出现错误！"); }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
